***********************************************************************************************
																							  *
* Forced Displacement and Asylum Policy in the Developing World							 	  *
																							  *
* Christopher W. Blair, Guy Grossman, and Jeremy Weinstein									  *
* cwblair@sas.upenn.edu																	      *
* May 2021															    					  *
																							  *
***********************************************************************************************

clear all
set more off
set scheme plotplainblind
macro drop _all
estimates drop _all
set matsize 800
set seed 8675309

** SET YOUR FILE PATH

cd "~/Dropbox/Immigration/Analysis/Policy Diffusion/Replication Files/"

use "dwrap_index.dta"
estimates drop _all

xtset ccode2 year

global base "ihs_pop_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_aidgdp_5ma_wins cwbroad_lag1 ihs_tradeshare_lag1 russian polyarchy_lag1 exc1inc2_reg_lag1 ihs_iterate_lag1 reglib1last3 leglib1last3 daclib1last3"

global dv "change1 liberalization1 restriction1 change_50 liberalization_50 restriction_50 change_25 liberalization_25 restriction_25"


****************************************** FIGURE 4 **********************************************

preserve

sort ccode2 year

* gen diff=0
* by ccode: replace diff= icw_index_field2-icw_index_field2[_n-1]

gen pos1=10 if country=="Madagascar"
replace pos1=1 if country=="Algeria"
replace pos1=3 if country=="Algeria"
replace pos1=7 if country=="Ethiopia"
replace pos1=4 if country=="Mauritius"
replace pos1=5 if country=="Mauritius"
replace pos1=6 if country=="Mauritius"
replace pos1=8 if country=="Ethiopia"
replace pos1=8 if country=="Lesotho"
replace pos1=8 if country=="Burkina Faso"
replace pos1=8 if country=="Armenia" & dif>.9
replace pos1=11 if country=="Burkina Faso" & inrange(year, 1987,1990)
replace pos1=8 if country=="Togo"
replace pos1=8 if country=="Guinea"
replace pos1=6 if country=="Comoros"
replace pos1=8 if country=="Mozambique"
replace pos1=9 if country=="Guinea"
replace pos1=11 if country=="Mozambique"
replace pos1=8 if country=="Ghana"
replace pos1=8 if country=="Ivory Coast"
replace pos1=8 if country=="Uzbekistan"
replace pos1=7 if country=="Comoros"
replace pos1=8 if country=="Comoros"
replace pos1=1 if country=="Nigeria" & inrange(year, 1987,1990)
replace pos1=3 if country=="Nigeria" & inrange(year, 1987,1990)
replace pos1=8 if country=="Democratic Republic of the Congo"
replace pos1=8 if country=="Mali"
replace pos1=8 if country=="Togo" & year==1999
replace pos1=8 if country=="Namibia"
replace pos1=4 if country=="Togo" & year==1999
replace pos1=2 if country=="Togo" & year==1999
replace pos1=2 if country=="Togo" & year==2000
replace pos1=4 if country=="Togo" & year==2000
replace pos1=1 if country=="Kazakhstan" & year==2001
replace pos1=1 if country=="Kazakhstan" & year==1998
replace pos1=1 if country=="Kazakhstan" & year==1997
replace pos1=4 if country=="Kazakhstan" & inrange(year,1996,2000)
replace pos1=3 if country=="Kazakhstan" & inrange(year,1996,2000)
replace pos1=12 if country=="Tanzania" & inrange(year,1996,2000)
replace pos1=2 if country=="Tanzania" & inrange(year,1996,2000)
replace pos1=9 if country=="Kenya" & year==2006
replace pos1=9 if year==2017
replace pos1=9 if country=="Turkey" & year>2011
replace pos1=4 if country=="Azerbaijan" & year>2011
replace pos1=8 if country=="Sierra Leone"
replace pos1=3 if country=="Kazakhstan" & year>=2005
replace pos1=3 if country=="Gambia"
replace pos1=9 if country=="Burkina Faso" & year>=1995
replace pos1=7 if country=="Gambia"
replace pos1=12 if country=="Azerbaijan" & inrange(year,1992,1995)
replace pos1=2 if country=="Azerbaijan" & inrange(year,1990,1993)
replace pos1=2 if country=="Tajikistan" & inrange(year,1990,1995)
replace pos1=11 if country=="Turkmenistan" & inrange(year,1993,1999)
replace pos1=1 if country=="Turkmenistan" & inrange(year,1993,1999)
replace pos1=1 if country=="Cyprus" 
replace pos1=2 if country=="Cyprus" 
replace pos1=12 if country=="Mozambique"
replace pos1=11 if country=="Kenya" & year==2006
replace pos1=12 if country=="Kenya" & year==2006
replace pos1=8 if country=="Somlaia"
replace pos1=8 if country=="Somalia"
replace pos1=8 if country=="Kazakhstan" & year==2004
replace pos1=12 if country=="Somalia" & year<1981
replace pos1=6 if country=="Kenya" & year==2017
replace pos1=2 if country=="Nigeria" & year>2011
replace pos1=3 if country=="Nigeria" & year>2011

tw scatter diff year if change1==1, msymbol(o) mlabel(country) mlabs(tiny) mlabang(45) mlabvp(pos1) mlabp(1) ylabel(-0.7(.1)1, angle(h) tlength(*1.45)) ymtick(-0.7(.05)1, tlength(*1.75)) ytitle("Difference in Policy Score", size(medium)) xtitle("Year", size(medium)) xlabel(1951(6)2017, angle(h) tlength(*1.45)) xmtick(1951(1)2017, tlength(*1.75)) yline(.1414844, lcolor(cranberry%50) lpattern(- - -)) yline(-.1414844, lcolor(cranberry%50) lpattern(- - -))

restore

use "figure4.dta", replace

tw line stockmil civilwarbroad_num1 year, legend(off) ylabel(0(5)75, tlength(*1.45)) ymtick(0(1)75, tlength(*1.75)) xlabel(1951(6)2017, tlength(*1.45)) xmtick(1951(1)2017, tlength(*1.75)) text(52 1990 "# of Civil Wars") text(64 2010 "FDP Stock")


****************************************** FIGURE A.14 **********************************************

use "dwrap_index.dta", replace

preserve

gen change=1 if change1==1
gen liberalization=1 if liberalization1==1
gen restriction=1 if restriction1==1

graph bar (count) liberalization restriction, over(year) stack ylabel(0(1)5, angle(h) tlength(*1.45)) ytitle("# of +/- 1 SD Changes") asyvars bar(1, fcolor(cranberry)) bar(2, fcolor("102 153 255")) legend(ring(0) position(1) rows(2) label(1 "Liberalizing Changes") label(2 "Restrictive Changes"))

restore


************************************** TABLE A.17 **********************************************


estpost sum $dv $base

esttab using "sumstat.tex", label title(Summary Statistics) cells("count mean sd min max")


************************************** TABLE A.22 **********************************************


reg unrsdrole ihs_pop_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_aidgdp_5ma_wins cwbroad_lag1 ihs_tradeshare_lag1 polyarchy_lag1 exc1inc2_reg_lag1 ihs_iterate_lag1 if majorannintra_contig_lag1==1, cluster(ccode)
outreg2 using "~/Desktop/unrsd.tex", tex(land) label dec(3) replace ctitle(UN RSD) keep(ihs_pop_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_aidgdp_5ma_wins cwbroad_lag1 ihs_tradeshare_lag1 polyarchy_lag1 exc1inc2_reg_lag1 ihs_iterate_lag1) alpha(0.01, 0.05, 0.1) sym(***,**,*)

logit unrsdrole ihs_pop_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_aidgdp_5ma_wins cwbroad_lag1 ihs_tradeshare_lag1 polyarchy_lag1 exc1inc2_reg_lag1 ihs_iterate_lag1 if majorannintra_contig_lag1==1, cluster(ccode)
outreg2 using "~/Desktop/unrsd.tex", tex(land) label dec(3) append ctitle(UN RSD) keep(ihs_pop_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_aidgdp_5ma_wins cwbroad_lag1 ihs_tradeshare_lag1 polyarchy_lag1 exc1inc2_reg_lag1 ihs_iterate_lag1) alpha(0.01, 0.05, 0.1) sym(***,**,*)


************************************** TABLE A.23 - A.25 **********************************************


count if change1==1
count if change1==1 & majorannintra_contig_lag1==1
tabulate change1 majorannintra_contig_lag1, chi2
count if change1==1 & intrastate_contig_lag1==1
tabulate change1 intrastate_contig_lag1, chi2

count if liberalization1==1
count if liberalization1==1 & majorannintra_contig_lag1==1
tabulate liberalization1 majorannintra_contig_lag1, chi2
count if liberalization1==1 & intrastate_contig_lag1==1
tabulate liberalization1 intrastate_contig_lag1, chi2

count if restriction1==1
count if restriction1==1 & majorannintra_contig_lag1==1
tabulate restriction1 majorannintra_contig_lag1, chi2
count if restriction1==1 & intrastate_contig_lag1==1
tabulate restriction1 intrastate_contig_lag1, chi2


count if change_5==1
count if change_5==1 & majorannintra_contig_lag1==1
tabulate change_5 majorannintra_contig_lag1, chi2
count if change_5==1 & intrastate_contig_lag1==1
tabulate change_5 intrastate_contig_lag1, chi2

count if liberalization_5==1
count if liberalization_5==1 & majorannintra_contig_lag1==1
tabulate liberalization_5 majorannintra_contig_lag1, chi2
count if liberalization_5==1 & intrastate_contig_lag1==1
tabulate liberalization_5 intrastate_contig_lag1, chi2

count if restriction_5==1
count if restriction_5==1 & majorannintra_contig_lag1==1
tabulate restriction_5 majorannintra_contig_lag1, chi2
count if restriction_5==1 & intrastate_contig_lag1==1
tabulate restriction_5 intrastate_contig_lag1, chi2


*************************************** TABLE A.31 *********************************************

stset lib1_end, failure(compete==1)

stcrreg exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 numlib1, compete(compete==2 3 5) vce(cluster ccode2) noshr
outreg2 using "~/Desktop/crisks.tex", tex(land) label dec(3) replace ctitle(Liberalization) keep(exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 numlib1) alpha(0.01, 0.05, 0.1) addstat("Log Likelihood", e(ll))
estat ic

stset chg1_end, failure(compete==1)

stcrreg exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 numlib1, compete(compete==4) vce(cluster ccode2) noshr
outreg2 using "~/Desktop/crisks.tex", tex(land) label dec(3) append ctitle(Liberalization) keep(exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 numlib1) alpha(0.01, 0.05, 0.1) addstat("Log Likelihood", e(ll))
estat ic


stset ewlib1_end, failure(compete2==1)

stcrreg exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 ewnumlib1, compete(compete2==2 3 5) vce(cluster ccode2) noshr
outreg2 using "~/Desktop/crisks.tex", tex(land) label dec(3) append ctitle(Liberalization) keep(exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 ewnumlib1) alpha(0.01, 0.05, 0.1) addstat("Log Likelihood", e(ll))
estat ic

stset ewchg1_end, failure(compete2==1)
stcrreg exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 ewnumlib1, compete(compete2==4) vce(cluster ccode2) noshr
outreg2 using "~/Desktop/crisks.tex", tex(land) label dec(3) append ctitle(Liberalization) keep(exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 std_polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 majorannintra_contig_lag1 ewnumlib1) alpha(0.01, 0.05, 0.1) addstat("Log Likelihood", e(ll))
estat ic


*************************************** TABLE A.32 *********************************************

sort ccode2 year

heckman selectdiff2_chg l.icw_index_field2 exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins, select(selectlevel_chg = exc1inc2_reg_lag1 majorannintra_contig_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 russian) vce(cl ccode2)
outreg2 using "~/Desktop/select.tex", tex(land) label dec(3) replace ctitle(Heckman) keep(*) alpha(0.01, 0.05, 0.1)

cmp setup
cmp (selectdiff2_chg= l.icw_index_field2 exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins) (selectlevel_chg = exc1inc2_reg_lag1 majorannintra_contig_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1), ind($cmp_cont $cmp_probit) cluster(ccode2)
outreg2 using "~/Desktop/select.tex", tex(land) label dec(3) append ctitle(CMP) keep(* c.ihs_aidgdp_5ma_wins) alpha(0.01, 0.05, 0.1)

heckman selectcw2 exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 russian, select(selectcw = landcontig ihs_pop_lag1 ihs_gdppc_lag1 polyarchy_lag1 southasia mideast coldwar post911) vce(cl ccode2) diff
outreg2 using "~/Desktop/select.tex", tex(land) label dec(3) append ctitle(Heckman) keep(*) alpha(0.01, 0.05, 0.1)

cmp setup
cmp (selectcw2= exc1inc2_reg_lag1 ihs_aidgdp_5ma_wins ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1 ) (selectcw =landcontig ihs_pop_lag1 ihs_gdppc_lag1 polyarchy_lag1 southasia mideast coldwar post911), ind($cmp_cont $cmp_probit) cluster(ccode2)
outreg2 using "~/Desktop/select.tex", tex(land) label dec(3) append ctitle(CMP) keep(*) alpha(0.01, 0.05, 0.1)

xtreg f.diff exc1inc2_reg_lag1##majorannintra_contig_lag1 c.ihs_aidgdp_5ma_wins##majorannintra_contig_lag1 ihs_gdppc_lag1 neggdpshock_lag1 ihs_pop_lag1 polyarchy_lag1 cwbroad_lag1 ihs_iterate_lag1 ihs_tradeshare_lag1, re vce(cl ccode)
outreg2 using "~/Desktop/ols.tex", tex(land) label dec(3) replace ctitle(OLS) keep(* exc1inc2_reg_lag1##majorannintra_contig_lag1 c.ihs_aidgdp_5ma_wins##majorannintra_contig_lag1) alpha(0.01, 0.05, 0.1)

